package com.generator.aboutUser.module.controller;

import com.generator.aboutUser.module.pojo.Module;
import com.generator.aboutUser.module.service.impl.ModuleService;
import com.generator.aboutUser.user.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @version 1.0
 * @auther wumei
 * @date 2022/10/01
 * 星期六 21:50
 */
@Controller
@RequestMapping("/module")
public class ModuleController {

    @Autowired
    private ModuleService moduleService;

    public ModuleService getModuleService() {
        return moduleService;
    }
    public void setModuleService(ModuleService moduleService) {
        this.moduleService = moduleService;
    }

    /**
     * 根据用户查询对应模块
     * @param session
     * @return  返回当前登录用户的模块集合
     */
    @ResponseBody
    @RequestMapping("/getModulesByUser")
    public Module[][] getModulesByUser(HttpSession session){

        Users user = (Users) session.getAttribute("user");
        Module[][] modulesByUser = null;
        if (user != null){
            modulesByUser  = moduleService.getModulesByUser(user);
            for (int i = 0; i < 5; i++) {
                for (int j = 0; j < 10; j++) {
                    if (modulesByUser[i][j]!=null){
                        System.out.print(modulesByUser[i][j]+"   ");
                    }
                }
                System.out.println("-----------");
            }
        }

        return modulesByUser;

    }


}
